package com.sf.web.controller;

import com.sf.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@CrossOrigin
public class LoginController {

    /**
     * /login
     * 参数 username   password
     * {success:true/false,msg:登录成功/登录失败，date：username/null}
     */
     @RequestMapping("/login")
     @ResponseBody
     public JsonResult login(String username, String password, HttpSession session){
       //判断账号密码是否是admin 123
         if("admin".equals(username)&&"123".equals(password)){
             //将username 放进session 中，为了后面登录拦截做铺垫
             session.setAttribute("USERNAME_IN_SESSION",username);
             return new JsonResult(true,"登录成功",username);
         }else {
             return new JsonResult(false,"账号密码错误",null);
         }
     }
}
